package com.qdairlines.controller;

import com.qdairlines.common.Response;
import com.qdairlines.controller.base.BaseController;
import com.qdairlines.entity.exflightinform.AbnormalFlight;
import com.qdairlines.service.exflightinform.ExFlightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * Created by yanxiguo on 2017/9/20.
 */
@Controller
public class ExceptionalFlightController  extends BaseController{

    @Autowired
    private ExFlightService exFlightService;

    @RequestMapping("exFlights/toPage")
    public String toPage(HttpServletRequest request, Model model,
                         HttpServletResponse response) throws Exception {
        return "/ex_flights";
    }

    @RequestMapping("exFlights")
    @ResponseBody
    public Response getFlightInfo(@RequestParam(value = "flightDate" ,required = true)String flightDate,
                                  @RequestParam(value="flightNo",required=false) String flightNo){
        Response response=new Response();
        List<AbnormalFlight>abnormalFlights=exFlightService.getAbnormalFlights(flightDate,flightNo);
        response.setResult(abnormalFlights);
        return  response;
    }

}
